public class NewFile {
	
	private static int findPosition(int []array) {
		
		int result = -1;
		int l = 0;
		int r = array.length;
		
		while(l <= r) {
			int m = (l+r) >> 1;
			if (m > 0 && array[m] == 1 && array[m-1] == 0) {
				result = m;
				break;
			} else {
				if(array[m] == 1) {
					r = m - 1;
				}
				else {
					l = m + 1;
				}
			}
		}
		
		return result;
	}

	/**
	 * Given an infinite size array with only 0s and 1s and sorted. find the
	 * transition point where 0s end or 1s start (written test question. coding)
	 */
	public static void main(String[] args) {

		int []array = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1};
		
		System.out.println(findPosition(array));
		
	}

}
